import React, { lazy } from "react";
import { Route } from "react-router-dom";


export let routes = [
  {
    path: "/list",
    key: "list",
    name: "list",
    children:[
      {
        path: "/list/list1",
        key: "list/list1",
        name: "list1",
      },
      {
        path: "/list/list2",
        key: "list/list2",
        name: "list2",
      }
    ]
  },
  {
    path: "/news",
    key: "news",
    name: "news",
  },
  {
    path: "/about",
    key: "about",
    name: "about",
  },
];

let staticRoutees = [
  {
    path: "*",
    key: "NotFound",
    name: "NotFound",
  },
]

export let createRouter = (routes) => {
  return (
    <>
      {routes &&
        routes.map((route) => {
          const Element = React.lazy(() => import(`./../pages/${route.key}`));
          return <Route path={route.path} element={<Element />} key={route.key}>
                    {
                      Array.isArray(route.children) ? createRouter(route.children) : null
                    }
                </Route>
        })}
    </>
  );
};
